Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "rails routes --expanded" mode #32130

Merged
merged 1 commit into from Feb 28, 2018

Conversation

benoittgt
Copy link
Contributor

@benoittgt benoittgt commented Feb 27, 2018

Summary

When using rails routes with small terminal or complicated routes it can be very difficult to understand where a specific element is, especially when using header. psql had the same issue, that's why they created "expanded mode" long time ago that you can
switch using \x or by starting psql with

-x
--expanded

    Turn on the expanded table formatting mode. This is equivalent to the \x command.

The output is similar to one implemented here for rails routes:

db_user-# \du
List of roles
-[ RECORD 1 ]----------------------------------------------
Role name  | super
Attributes | Superuser, Create role, Create DB
Member of  | {}
-[ RECORD 2 ]----------------------------------------------
Role name  | role
Attributes | Superuser, Create role, Create DB, Replication
Member of  | {}

Here is an output expanded mode (I removed active storage routes):

$ rails routes --expanded
--[ Route 1 ]------------------------------------------------------------
Prefix            | high_scores
Verb              | GET
URI               | /high_scores(.:format)
Controller#Action | high_scores#index
--[ Route 2 ]------------------------------------------------------------
Prefix            | new_high_score
Verb              | GET
URI               | /high_scores/new(.:format)
Controller#Action | high_scores#new
--[ Route 3 ]------------------------------------------------------------
Prefix            | blog
Verb              |
URI               | /blog
Controller#Action | Blog::Engine

[ Routes for Blog::Engine ]
--[ Route 1 ]------------------------------------------------------------
Prefix            | cart
Verb              | GET
URI               | /cart(.:format)
Controller#Action | cart#show

Other Information

  • I didn't add an entry to changelog because it seems too early for me. Also, I didn't know where you want this to be targeted if it was approved.
  • App used to display routes

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @georgeclaghorn (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@jaredbeck
Copy link
Contributor

Good idea Benoit, this will be helpful. It'll be harder to grep this format, but we can't have everything. :)

@benoittgt
Copy link
Contributor Author

@jaredbeck you can still use '-c controller' or '-g pattern'

rails routes -g high --expanded
--[ Route 1 ]------------------------------------------------------------
Prefix            | high_scores
Verb              | GET
URI               | /high_scores(.:format)
Controller#Action | high_scores#index
--[ Route 2 ]------------------------------------------------------------
Prefix            | new_high_score
Verb              | GET
URI               | /high_scores/new(.:format)
Controller#Action | high_scores#new

@jaredbeck
Copy link
Contributor

@jaredbeck you can still use '-c controller' or '-g pattern'

Awesome. I had no idea about either of those, thanks.

Copy link
Member

@rafaelfranca rafaelfranca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Can you add a CHANGELOG entry to the railties changelog?

@@ -7,12 +7,14 @@ module Command
class RoutesCommand < Base # :nodoc:
class_option :controller, aliases: "-c", type: :string, desc: "Specifies the controller."
class_option :grep_pattern, aliases: "-g", type: :string, desc: "Specifies grep pattern."
class_option :expanded_format, aliases: "--expanded", type: :string, desc: "Specifies grep pattern."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that desc should be rewrited.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouppps correct

@benoittgt
Copy link
Contributor Author

benoittgt commented Feb 28, 2018

When it's good I can squash. Thanks to all of you for the reviews. 🤙🏻

When using rails routes with small terminal or complicated routes it can be
very difficult to understand where is the element listed in header. psql
had the same issue, that's why they created "expanded mode" you can
switch using `\x` or by starting psql with
```
-x
--expanded

    Turn on the expanded table formatting mode. This is equivalent to the \x command.
```
The output is similar to one implemented here for rails routes:

db_user-# \du
List of roles
-[ RECORD 1 ]----------------------------------------------
Role name  | super
Attributes | Superuser, Create role, Create DB
Member of  | {}
-[ RECORD 2 ]----------------------------------------------
Role name  | role
Attributes | Superuser, Create role, Create DB, Replication
Member of  | {}
@benoittgt
Copy link
Contributor Author

Squashed 🎉

@rafaelfranca rafaelfranca merged commit c9fa561 into rails:master Feb 28, 2018
@benoittgt benoittgt deleted the rake-routes-compact-mode branch March 1, 2018 08:33
@Schwad
Copy link
Contributor

Schwad commented Mar 1, 2018

Really excited for this feature, thank you so much for your work. 🎆

bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Mar 5, 2018
bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Mar 13, 2018
- Create `Base` and inherit `Sheet` and `Expanded` in order to
- prevent code duplication.
  - Remove trailing "\n" for components of `Expanded`.
  - There is no need for `Expanded#header` to return `@buffer` so return `nil` instead.

- Change `no_routes` message "No routes were found for this controller"
  since if use `-g`, it sounds incorrect.
  - Display `No routes were found for this controller.` if apply `-c`.
  - Display `No routes were found for this grep pattern.` if apply `-g`.

Related to rails#32130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants